const state = {
  novelList: [],
  currentNovel: null,
  categories: [],
  authors: [],
  loading: false,
  pagination: {
    current: 1,
    pageSize: 10,
    total: 0
  }
};

const mutations = {
  SET_NOVEL_LIST: (state, list) => {
    state.novelList = list;
  },
  SET_CURRENT_NOVEL: (state, novel) => {
    state.currentNovel = novel;
  },
  SET_CATEGORIES: (state, categories) => {
    state.categories = categories;
  },
  SET_AUTHORS: (state, authors) => {
    state.authors = authors;
  },
  SET_LOADING: (state, loading) => {
    state.loading = loading;
  },
  SET_PAGINATION: (state, pagination) => {
    state.pagination = pagination;
  }
};

const actions = {
  // 获取小说列表
  async fetchNovelList({ commit }, params) {
    commit('SET_LOADING', true);
    try {
      // TODO: 调用API获取小说列表
      // const res = await api.novel.getList(params);
      // commit('SET_NOVEL_LIST', res.data.list);
      // commit('SET_PAGINATION', {
      //   current: params.page,
      //   pageSize: params.pageSize,
      //   total: res.data.total
      // });
    } catch (error) {
      console.error('获取小说列表失败:', error);
    }
    commit('SET_LOADING', false);
  },

  // 获取小说详情
  async fetchNovelDetail({ commit }, id) {
    try {
      // TODO: 调用API获取小说详情
      // const res = await api.novel.getDetail(id);
      // commit('SET_CURRENT_NOVEL', res.data);
    } catch (error) {
      console.error('获取小说详情失败:', error);
    }
  },

  // 获取分类列表
  async fetchCategories({ commit }) {
    try {
      // TODO: 调用API获取分类列表
      // const res = await api.category.getList();
      // commit('SET_CATEGORIES', res.data);
    } catch (error) {
      console.error('获取分类列表失败:', error);
    }
  },

  // 获取作者列表
  async fetchAuthors({ commit }) {
    try {
      // TODO: 调用API获取作者列表
      // const res = await api.author.getList();
      // commit('SET_AUTHORS', res.data);
    } catch (error) {
      console.error('获取作者列表失败:', error);
    }
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
}; 